import java.io.IOException;
import java.util.Vector;


public class newPredictor {
	private int id;
	private int prediction;
	private int bit0 =0, bit1=0, bit2=0;
	private Vector<BT>  BTB;
	private int count0;
	private int count1;

	public newPredictor (int i) {
		this.id = i;
		BTB = new Vector<BT>();
		count0=0;
		count1=0;

	}

	int add (String BIA, String BTA) {
		BT newBT = new BT();newBT.BIA = BIA; newBT.BTA=BTA;
		int index=0;
		boolean found =false;
		for( int i=0; i<BTB.size(); i++) {
			if(BTB.elementAt(i).BIA.compareTo(BIA) == 0 && 
					BTB.elementAt(i).BTA.compareTo(BTA) == 0) {
				found = true;
				index =  i;
				break;
			}
		} if( found == false) {
			BTB.add(newBT);
			index = BTB.size()-1;
		}
		return index;
		//System.out.println(BTB.size()+" instructions");
	}


	int predict (String BIA, String BTA, int id) throws IOException {
		int bit=0; int bit1=0;
		boolean found = false;
		int index = 0;
		for( int i=0; i<BTB.size(); i++) {
			if(BTB.elementAt(i).BIA.compareTo(BIA) == 0 && 
					BTB.elementAt(i).BTA.compareTo(BTA) == 0) {
				found = true;
				index = i;
				break;
			}
		} if( found == true) {
			bit0 = BTB.elementAt(index).bit0;
			bit1 = BTB.elementAt(index).bit1;
			
			if(bit0==0 && bit1==0) {
				prediction = 0;
				count0++;
			} else if(bit0==1 && bit1==0){
				prediction =0;
				count0++;
			} else {
				prediction =1;
				count1++;
			}
			/*
			if( BTB.elementAt(index).bit0 != BTB.elementAt(index).bit1 ) {
				if(count1>count0) prediction = 0;
				else prediction = 1;
			}
			*/
			//System.out.print(" ["+BIA+", "+BTA+"] "+":"+prediction);
		} else{
			System.out.println("NOT FOUND");
			System.in.read();
		}
		return prediction;
	}

	void update(int id, int outcome) {
		boolean found = false;
		int index=0;
		
		//System.out.println("/ "+outcome);
		BTB.elementAt(id).bit0 = BTB.elementAt(id).bit1;
		BTB.elementAt(id).bit1 = outcome;
	}


}
